document.write('<link rel="stylesheet" type="text/css" href="component/dhtmlx3.5/dhtmlxCalendar_pro/dhtmlxcalendar.css"></link>');
document.write('<link rel="stylesheet" type="text/css" href="component/dhtmlx3.5/dhtmlxCalendar_pro/skins/dhtmlxcalendar_dhx_terrace.css"></link>');
document.write('<script src="component/dhtmlx3.5/dhtmlxCalendar_pro/dhtmlxcalendar.js"></script>');
/**
 * config可以是string型也可以是{}object/json形式
 * string时候就是input的id
 * 
 * config为object/json时 属性有
 * ｛
 * 		id			:'',input id
 * 		format 	: '',日期格式 %Y 年、%m 月、%d 日、%H 小时、%i 分钟、%s 秒
 * 		value		: ''初始化日期框的值 可以是Date类型 也可以是日期格式的字符串  2011-08-08
 * ｝
 * @param {} config
 * @return {}
 */	
var CalendarInputObject	= function(config){
	if(!dhtmlXCalendarObject.prototype.langData["cn"])
		dhtmlXCalendarObject.prototype.langData["cn"] = {
		     //date format
			dateformat: '%Y-%m-%d',
			//full names of months
		        monthesFNames: ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],
			//shortened names of months
		        monthesSNames: ["1","2","3","4","5","6","7","8","9","10","11","12"],
			//full names of days
		        daysFNames: ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
			//shortened names of days
		        daysSNames: ["日","一","二","三","四","五","六"],
		        //starting day of a week. Number from 1(Monday) to 7(Sunday)
			weekstart: 7
		};
	this.calendar	= null;
	this.format	= config.format || "%Y-%m-%d";
	this.value	= "";
	if(typeof (config) =="string" )	{
		this.calendar	= new dhtmlXCalendarObject(config);
		this.setSkin();
	}
	if(typeof (config) =="object" ){
		this.id	= config.id;
		this.calendar	= new dhtmlXCalendarObject(this.id);
		if(config.value){
			this.value	= config.value;
			if(this.value instanceof Date){
				var o = {
					"%Y": this.value.getFullYear(),
					"%M" : this.value.getMonth() + 1,
					"%m" : this.value.getMonth() + 1,
					"%d" : this.value.getDate(),
					"%h" : this.value.getHours() % 12 == 0 ? 12 : this.value.getHours() % 12,
					"%H" : this.value.getHours(),
					"%i" : this.value.getMinutes(),
					"%s" : this.value.getSeconds(),
					"%S" : this.value.getMilliseconds()
				};
				var b	= false;
				for(var i in o){
					if(b==false){
						this.value	= this.format.replace(i,o[i]);
						b	= true;
					}else{
						this.value	= this.value.replace(i,o[i]);
					}
				}		
			}
			this.setValue(this.value);
			this.setSkin();
		}
	}
	this.calendar.setDateFormat(this.format);
	this.calendar.loadUserLanguage('cn');
	this.calendar.setSkin('dhx_terrace');
	return this.calendar;
};
CalendarInputObject.prototype = {
	setDataFormat	: function(format){
		this.format	= format;
		this.calendar.setDateFormat(this.format);
	},
	setValue : function(value){
		this.value	= value;
		document.getElementById(this.id).value	= this.value;
		this.calendar.setDate(this.value);
	},
	getValue : function(){
		return this.value;
	},
	getDataFormat : function(){
		return this.format;
	},
	reset : function(){
		
	}
};